<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function add(a, b, c, d) {
        return a + b + c + d;
      }
      // console.log(add(1, 2, 3, 4));
      function FixedParmsCurry(fn) {
        var _args = [...arguments].slice(1);
        return function () {
          var newArr = _args.concat([...arguments]);
          console.log(newArr);
          return fn.apply(this, newArr);
        };
      }

      function curry(fn, length) {
        var length = length || fn.length;
        return function () {
          if (arguments.length < length) {
            var combine = [fn].concat([].slice(arguments, 0));
            return curry(FixedParmsCurry(combine), length - arguments.length);
          } else {
            fn.apply(this, arguments);
          }
        };
      }
      var after = FixedParmsCurry(add, 1, 2);
      console.log(after(3, 4));
    </script>
  </body>
</html>
